package com.rsk.shiro;

import java.util.Collection;
import java.util.Set;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;

import com.rsk.shiro.common.ShiroConst;
import com.rsk.shiro.jwt.JwtUtil;


/**
 * 重写Shiro的Cache保存读取
 */
public class ShiroCache<K, V> implements Cache<K, V> {


    //@Autowired
    //private RedisUtils redisUtils;

	/**
	 * 缓存的key名称获取为shiro:cache:account
	 */
	@SuppressWarnings("unused")
	private String getKey(Object key) {
		return ShiroConst.shiro_redis + JwtUtil.getClaim(key.toString(), ShiroConst.account);
	}

	/**
	 * 获取缓存
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Object get(Object key) throws CacheException {
		//if (!redisUtils.hasKey(this.getKey(key))) {
			return null;
		//}
		//return redisUtils.get(this.getKey(key));
	}

	/**
	 * 保存缓存
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Object put(Object key, Object value) throws CacheException {
		//return redisUtils.set(this.getKey(key), value, ShiroConst.shiroCacheExpireTime);
		return null;
	}

	/**
	 * 移除缓存
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Object remove(Object key) throws CacheException {
		/*if (!redisUtils.hasKey(this.getKey(key))) {
			return null;
		}
		redisUtils.del(this.getKey(key));*/
		return null;
	}

	/**
	 * 清空所有缓存
	 */
	@Override
	public void clear() throws CacheException {
		// TODO Auto-generated method stub

	}

	/**
	 * 缓存的个数
	 */
	@Override
	public Set<K> keys() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * 获取所有的key
	 */
	@Override
	public int size() {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * 获取所有的value
	 */
	@Override
	public Collection<V> values() {
		// TODO Auto-generated method stub
		return null;
	}
}